<#include "../../common/_header.htm">
<div id="hidebox" style="height:100%;width:100%">
	<div class="box">
		<div class="box-header">
			<div class="row RowSearchWork">
				<div class="col-sm-12">
					<div class="form-group">
                        <div class="form-inline">
							<div class="form-group">
								<label class="control-label hidden-xs">手机号码</label>
								<input type="text" class="form-control" name="serviceNumber" value="" placeholder="手机号码" />
							</div>
							<div class="form-group bill-buttonarea ml10"  style="text-align: center;">
								<input type="button" class="btn btn-primary" onclick="queryList();" value="查询" />
							</div>
                        </div>
                   </div>
				</div>
			</div>
		</div>
	</div>
	<table id="dg3"></table>
</div>
<script>
	/** 页面加载完毕，回显传值 **/
	var dialog = top.dialog.get(window);
	var fileUuids = dialog.data.fileUUids;
	fileUuids = fileUuids.join(",");
	var casemanagerId = dialog.data.casemanageId;
	var rowNumber = 0;
	/*证件类型封装*/
	var idTypeSelect = [];
	window.onload= firstTable;
	function queryList(){
        firstTable();
	}
	function firstTable() {
		var serviceNumber = $('input[name="serviceNumber"]').val();
		$('#dg3').datagrid({
	        url : "${ctx}/casemanage/findCaseObjectPhoneMapping",
	        method: 'post',
	        iconCls: 'icon-save',
	        queryParams:{//每次请求的参数
	        	casemanagerId: casemanagerId,
	            fileUuids : fileUuids,
	            serviceNumber :serviceNumber
	        },
			height:820,
	        pageList:[10,20,40,50,100],//每页记录数选择范围设置
	        pageNumber:1,//当前页号,
	        pageSize:20,//每页显示记录数
	        loadMsg:"正在加载，请稍后",//加载数据时的提示信息
	        emptyMsg:"暂无信息",//加载数据为空时的信息
	        rownumbers:true,//序号
	        fitColumns: true,//使表格自适应页面宽度
	        pagination: true,//是否分页
	        singleSelect: true,
	        idField: 'serviceNumber',
	        columns:[[ //每一列的具体设置。
	            {
		        	field:'serviceNumber',
		        	title:'手机号码',
		        	width:'20%'
	        	},
	            {
	            	field:'personName',
	            	title:'案件对象名称',
	            	width:'20%',
	            	editor :{
	            		type : "text",
	            		options : {
	            			validType:"personName"
	            		}
	            	}
	           	},
	            {
	           		field:'idType',
	           		title:'证件类型',
	           		width:'20%',
	           		editor:{
						type:'combobox',
						options:{
							valueField: 'idType',
							data: idTypeSelect,
							valueField: "value",
	       					textField: "text"
						}
					}
	       		},
	            {
	            	field:'idNumber',
	            	title:'证件号码',
	            	width:'20%',
	           		editor :{
	               		type : "validatebox",
	               		options : {
	               			validType:"idNumber"
	               		}
	               	}
	           	},
	           	{field:'opt',title:'操作',align:'center', width:'20%',sortable:false,align:'center', 
	            	formatter:function(value,row,index){  
	            	     var btn = '<a href="#" id="bj'+index+'" onclick="edit(\''+index+'\');">编辑</a> '
	            	        + '<a href="#" id="bc'+index+'" style="display:none" onclick="save(\''+index+'\');">保存</a>'
	            	        + '&nbsp;&nbsp;&nbsp;&nbsp;<a href="#" id="qx'+index+'" style="display:none" onclick="cancel(\''+index+'\');">取消</a>'; 
	                	 return btn;
	            	}
				}
	        ]],
	        onLoadSuccess: function(data){
	        }
	    });
	}

	function edit(index){
	   $('#dg3').datagrid('updateRow',{
		   index : parseInt(index),
	       row : {
	    	   idType: ''    //更新的值  
	       }
	   });
	   $('#bj' + index).hide();
	   $('#bc' + index).show();
	   $('#qx' + index).show();
	   
	   //启动编辑
	   $('#dg3').datagrid('beginEdit',index);
	   globalIndex =index;
	   $("#dg3").datagrid("selectRow",globalIndex);
	   getIdType(); 
   }
   //加载combobox的下拉列表
   function getIdType(){
	   $.ajax({
	        url : "${ctx}/casemanage/findIdType",
	        type : "get",
	        async : false,
	        dataType :'json',
	        success : function (obj) {
	        	if(obj.length){
	        		$.each(obj ,function (i,n) {
	        			var c = {"value":n,"text":n};
	        			idTypeSelect.push(c);
		            });
	        	}else{
	        		idTypeSelect = [{"value":"居民身份证","text":"居民身份证"},
	        			{"value":"统一社会信用证","text":"统一社会信用证"},
	        			{"value":"全国组织机构代码证书","text":"全国组织机构代码证书"},
	        			{"value":"户口薄","text":"户口薄"},
	        			{"value":"台湾居民来往大陆通行证","text":"台湾居民来往大陆通行证"},
	        			{"value":"临时居民身份证","text":"临时居民身份证"}];
	        	}
	        }
	    });
	    var ed = $("#dg3").datagrid('getEditor', {index: globalIndex,field: 'idType'}); 
		$(ed.target).combobox({
			data: idTypeSelect,
			panelHeight: '200',
			editable: false,
			multiple: false,
			valueField: 'value', 
	        textField: 'text'
		 });
	}
	//保存
    function save(index){
		debugger
		$('#dg3').datagrid('endEdit', globalIndex);//结束编辑
		//获得修改数据  
        var updated = $('#dg3').datagrid('getChanges', "updated");  
        var data = {"serviceNumber": updated[0].serviceNumber,"personName": updated[0].personName,"idType": updated[0].idType,"idNumber": updated[0].idNumber,"casemanagerId": casemanagerId};
		$.ajax({
		    url:"${ctx}/casemanage/saveCaseObject4Phone",//保存人员类别
			type:"POST",
			contentType: "application/json;charset=UTF-8",
	        data : JSON.stringify(data),// 参数封装
			success:function(result){
				if(result.result){
					$('#dg3').datagrid('cancelEdit',index);
					$('#dg3').datagrid('reload');//刷新
					toastr.success("保存成功","提示信息");
				}else{
					toastr.error("保存失败","提示信息");
				}
			}
		});	
	}
   //取消
   function cancel(index){
		$('#dg3').datagrid('cancelEdit',index);
		$('#dg3').datagrid('reload');
	}
</script>
<style>
</style>
</body>
</html>